﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using YAPL.Language.Ast;
using YAPL.Language.Ast.Transformation;
using YAPL.Language.Core;

namespace YAPL.Test.YAPL.Language.Ast.Transformation {
	public class FunctionPrecomputationTransformTest {

		[Fact]
		public void PowFunctionCallWithConstantParametersShouldBeTrasformedIntoConstant() {
			var c1 = Expressions.Integer(2);
			var c2 = Expressions.Integer(3);
			var call = Expressions.FunctionCall(FunctionNames.Pow, new List<Expression> {c1, c2});
			IAstTransform i = new FunctionPrecomputationTransform();
			var result = i.Transform(call);
			Assert.IsType(typeof(ConstantExpression), result);
			var constant = (ConstantExpression)result;
			Assert.IsType(typeof(int), constant.Value);
			Assert.Equal(8, (int)constant.Value);
		}
	}
}
